/**
 * $Id: GuiceServletConfig.java 2 2011-09-03 10:16:43Z adriftrock@gmail.com $
 */

package com.swehr.jersey;

/**
 * @author Rock Huang
 * @version 0.1
 */

import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.servlet.GuiceServletContextListener;
import com.google.inject.servlet.ServletModule;
import com.sun.jersey.guice.spi.container.servlet.GuiceContainer;
import com.swehr.server.daos.IOrganizationDao;
import com.swehr.server.daos.IPersonnelDao;
import com.swehr.server.daos.IPositionDao;
import com.swehr.server.daos.impl.OrganizationDao;
import com.swehr.server.daos.impl.PersonnelDao;
import com.swehr.server.daos.impl.PositionDao;
import com.swehr.server.services.IPersonnelService;
import com.swehr.server.services.impl.PersonnelService;

import java.util.HashMap;
import java.util.Map;

public class GuiceServletConfig extends GuiceServletContextListener {

    @Override
    protected Injector getInjector() {
        return Guice.createInjector(new ServletModule() {

            @Override
            protected void configureServlets() {
                bind(IOrganizationDao.class).to(OrganizationDao.class);
                bind(IPersonnelService.class).to(PersonnelService.class);
                bind(IPersonnelDao.class).to(PersonnelDao.class);
                bind(IPositionDao.class).to(PositionDao.class);

                Map<String, String> params = new HashMap<String, String>();
                params.put("com.sun.jersey.config.property.packages",
                        "com.swehr.jersey;com.swehr.server.resources");
                serveRegex("/(images|css|javascript)/.*").with(DefaultWrapperServlet.class);
                serve("/*").with(GuiceContainer.class, params);
            }
        });
    }
}
